package fasilkom.antz;

import java.awt.Graphics2D;
import java.awt.event.KeyEvent;

import com.golden.gamedev.GameObject;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.background.ImageBackground;

public class GameMenu extends GameObject {
	
	Background background;
	
	Sprite mousePointer;
	Sprite pointer;
	
	public GameMenu(Antz parent) {
		super(parent);
	}
	
	public void initResources() {
		background = new ImageBackground(getImage("assets/MenuGame.jpg"));
		pointer = new Sprite(getImage("assets/pointer2.png"));
		pointer.setBackground(background);
		pointer.setLocation(300, 305);
		
		// Mouse pointer
		mousePointer = new Sprite(getImage("assets/pointer.png"));
	}
	
	public void render(Graphics2D g) {
		background.render(g);
		pointer.render(g);
		
		// Mouse pointer
		mousePointer.render(g);
	}
	
	public void update(long elapsedTime){
		background.update(elapsedTime);
		pointer.update(elapsedTime);
		updateMouseControl(elapsedTime);
		keyboardControl(elapsedTime);
		
		// Mouse pointer
		mousePointer.setLocation(getMouseX(), getMouseY());
		mousePointer.update(elapsedTime);
	}
	
	private void updateMouseControl(long elapsedTime) {
		int y = getMouseY();
		if (y >= 305 && y < 360) {
			pointer.setLocation(pointer.getX(), 305);
		} else if (y >= 360 && y < 415) {
			pointer.setLocation(pointer.getX(), 360);
		}
	}

	public void keyboardControl(long elapsedTime){
		if(pointer.getY() == 305 && (keyPressed(KeyEvent.VK_UP) || keyPressed(KeyEvent.VK_DOWN)) ){
			pointer.setLocation(pointer.getX(), 360);
		}
		else if(pointer.getY() == 360 && (keyPressed(KeyEvent.VK_UP) || keyPressed(KeyEvent.VK_DOWN)) ){
			pointer.setLocation(pointer.getX(), 305);
		}
		
		// kalu new game pindah scene
		if(pointer.getY() == 305 && (keyPressed(KeyEvent.VK_ENTER) || click())){
			parent.nextGameID = Antz.INTRO_STORY;
			finish();
			System.out.println("cupu");
		}
		
	}

}
